<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Controller;

use Think\Page;

/**
 * 后台用户控制器
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class NoticeController extends AdminController
{
    //单位表
    private $infoModel;
    //单位配置表
    private $infoConfModel;
    //省市区表
    private $districtModel;
    public function __construct()
    {
        parent::__construct();
        $this->infoModel    = M('notice');
        $this->journalModel = M('journal');
        // $this->infotypeModel = M('information_type');
        // $this->journalModel->create();
        // $this->infotypeModel->create();
    }
    public function journal()
    {
        $Page          = new Page($count, 10); // 实例化分页类 传入总记录数和每页显示的记录数
        $show          = $Page->show(); // 分页显示输出
        $count         = $this->journalModel->count(); //查询总记录数
        $this->journal = $this->journalModel->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')->select(); //$_POST 是查询条件
        $this->display();

    }
    public function index()
    {
        if (I('keyword')) {
            $keyword               = I('keyword');
            $data['title|content'] = array('like', '%' . $keyword . '%');
            // $this->assign('keyword', $keyword);
        }
        if (I('area')) {
            $data['area_id'] = I('area');
        }
        if (I('start') && I('end')) {
            $data['ctime'] = array(between, array(strtotime(I('start')), strtotime(I('end'))));
        }
        $params = array(
            'keyword' => I('keyword'),
            'area'    => I('area'),
            'start'   => I('start'),
            'end'     => I('end'),
        );
        // dump($_POST);
        $Page     = new Page($count, 10, $params); // 实例化分页类 传入总记录数和每页显示的记录数
        $show     = $Page->show(); // 分页显示输出
        $count    = $this->infoModel->where($data)->count(); //查询总记录数
        $infoList = $this->infoModel->where($data)->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')->select(); //$_POST 是查询条件
        foreach ($infoList as $key => $value) {
            $leave = M('area')->where('areaID = ' . $value['area_id'])->getField('area');
            //$username               = get_username($value['uid']);
            $infoList[$key]['area_name'] = $leave;
        }
        // dump($infoList);exit();
        $areas = M('area')->where('father=370300')->select();
        $this->assign('areas', $areas);
        $this->assign('list', $infoList);
        $this->assign('_page', $show);
        $this->display();
    }

    public function editnotice()
    {

        if (IS_POST) {
            // $data['starttime']    = strtotime(I('starttime'));
            // $data['applyendtime'] = strtotime(I('applyendtime'));
            $ids             = I('area_id');
            $data['area_id'] = implode(',', $ids);
            parent::savedata('notice', $data, 'index');
        }
        $areas = M('area')->where('father=370300')->select();
        $this->assign('areas', $areas);
        // dump($areas);
        $id           = I('get.id');
        $model_object = D('notice');
        $data         = $model_object->find($id);
        $this->aaa    = explode(',', $data['area_id']);
        $this->assign('typeList', $typeList);
        $this->assign('data', $data);

        $this->display();
    }

    public function addnotice()
    {
        if (IS_POST) {
            // $data['starttime']    = strtotime(I('starttime'));
            // $data['applyendtime'] = strtotime(I('applyendtime'));

            $ids             = I('area_id');
            $data['area_id'] = implode(',', $ids);
            parent::adddata('notice', $data, 'index');
        }
        $areas = M('area')->where('father=370300')->select();
        $this->assign('areas', $areas);
        $this->display();
    }
    /**
     * 删除后台菜单
     * @author yangweijie <yangweijiester@gmail.com>
     */
    public function del()
    {
        if (M('notice')->where('id = ' . I('id'))->delete()) {
            $this->success('删除成功');
        } else {
            $this->error('删除失败！');
        }
    }
}
